<template>
	<view class="index">
		<!-- 搜索的组件 -->
		<my-search></my-search>
		<!-- 轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular="true" class="swiper">
			<swiper-item v-for="item,index in bannerList" :key="index" class="swiper-item">
				<image :src="item.carouselUrl" mode="" class="img"></image>
			</swiper-item>
			
		</swiper>
		<!-- nav 导航 -->
		<view class="nav">
			<view class="nav-item" v-for="item,index in navList" :key="item.categoryId">
				<image :src="item.imgUrl" mode="" class="img"></image>
				<view class="name">
					{{item.name}}
				</view>
			</view>
		</view>
		
		<view class="news-title">
			新品上线
		</view>
		<!-- 商品列表 -->
		<view class="news">
			<view class="news-item" v-for="item,index in goodsList" :key="item.goodsId">
				<image :src="item.goodsCoverImg" mode="" class="img"></image>
				<view class="title">
					{{item.goodsName}}
				</view>
				<view class="price">
					{{item.sellingPrice}}
				</view>
			</view>
		</view>
		
		
	</view>
</template>

<script>
	import {getData} from '../../utils/api.js'
	import mySearch from '../../components/mySearch.vue'
	import data from '../../static/data.js'
	export default {
		data() {
			return {
				title: 'Hello',
				bannerList:[],//存放轮播图
				goodsList:[],
				navList:[]
			}
		},
		components:{
			mySearch
		},
		onLoad() {
			// 导航栏的数据
			this.navList = data.iconList
			
             getData().then(res=>{
				 console.log(res);
				 this.bannerList = res.carousels
				 this.goodsList = res.newGoodses
				
			 })
			
			 
		},
		methods: {

		}
	}
</script>

<style lang="scss">
.swiper{
	width: 100%;
	height: 400rpx;
	.swiper-item{
		width: 100%;
		height: 100%;
		.img{
			width: 100%;
			height: 100%;
		}
	}
}
.nav{
	width: 100%;
	display: flex;
	box-sizing: border-box;
	padding: 10rpx 20rpx;
	align-items: center;
	justify-content: space-around;
	flex-wrap: wrap;
	.nav-item{
		text-align: center;
		margin-top: 10rpx;
		font-size: 28rpx;
		width: 20%;
		.img{
			width: 70rpx;
			height: 70rpx;
		}
	}
}
.news-title{
	height: 80rpx;
	line-height: 80rpx;
	background-color: #f5f5f5;
	text-align: center;
}
.news{
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	box-sizing: border-box;
	padding: 0 20rpx;
	flex-wrap: wrap;
	.news-item{
		width: 50%;
		font-size: 28rpx;
		margin: 10px 0;
		.img{
			width:375rpx;
			height: 375rpx;
			
		}
	}
}
</style>
